package com.qf.air.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <beans   约束.....>
 *
 *   <bean id="" class="" />
 * </beans>
 *
 *
 *
 */
@Configuration     // <beans .....  代表这个类是一个配置类
public class ElaticsearchConfig {

    @Value("${es.host}")   // ${es.host}   引入了加载过的properties文件中的value值
    private String host;

    @Value("${es.port}")   // ${es.port}
    private Integer port;

    @Bean  // <bean id="restHighLevelClient" class="org.elasticsearch.client.RestHighLevelClient" />
    public RestHighLevelClient restHighLevelClient(){
        HttpHost httpHost = new HttpHost(host,port);

        RestClientBuilder restClientBuilder = RestClient.builder(httpHost);

        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);

        return restHighLevelClient;
    }
}
